<template>
    <div>
        <table class="wq text-center" border="0" cellpadding="0" cellspacing="1">
            <tr class="t_list_caption">
                <td colspan="12">总和、总和过关</td>
            </tr>
            <tr class="t_td_text">
                <td width="10%" class="caption_1">总和大</td>
                <td class="colorRed bolds odds">{{ratedata['总和:大小:大']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['总和:大小:大']" @focus="quickbetFuns($event,'总和:大小:大')"></td>
                <td width="10%" class="caption_1">总和小</td>
                <td class="colorRed bolds odds">{{ratedata['总和:大小:小']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['总和:大小:小']" @focus="quickbetFuns($event,'总和:大小:小')"></td>
                <td width="10%" class="caption_1">总和单</td>
                <td class="colorRed bolds odds">{{ratedata['总和:单双:单']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['总和:单双:单']" @focus="quickbetFuns($event,'总和:单双:单')"></td>
                <td width="10%" class="caption_1">总和双</td>
                <td class="colorRed bolds odds">{{ratedata['总和:单双:双']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['总和:单双:双']" @focus="quickbetFuns($event,'总和:单双:双')"></td>
            </tr>
            <tr class="t_td_text">
                <td width="10%" class="caption_1">总和810</td>
                <td class="colorRed bolds odds">{{ratedata['总和:810:$fn']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['总和:810:$fn']" @focus="quickbetFuns($event,'总和:810:$fn')"></td>
                <td colspan="9"> </td>
            </tr>
            <tr class="t_td_text">
                <td width="10%" class="caption_1">总大单</td>
                <td class="colorRed bolds odds">{{ratedata['总和:过关:大单']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['总和:过关:大单']" @focus="quickbetFuns($event,'总和:过关:大单')"></td>
                <td width="10%" class="caption_1">总大双</td>
                <td class="colorRed bolds odds">{{ratedata['总和:过关:大双']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['总和:过关:大双']" @focus="quickbetFuns($event,'总和:过关:大双')"></td>
                <td width="10%" class="caption_1">总小单</td>
                <td class="colorRed bolds odds">{{ratedata['总和:过关:小单']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['总和:过关:小单']" @focus="quickbetFuns($event,'总和:过关:小单')"></td>
                <td width="10%" class="caption_1">总小双</td>
                <td class="colorRed bolds odds">{{ratedata['总和:过关:小双']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['总和:过关:小双']" @focus="quickbetFuns($event,'总和:过关:小双')"></td>
            </tr>
        </table>

        <table class="wq text-center" border="0" cellpadding="0" cellspacing="1">
            <tr class="t_list_caption">
                <td colspan="9">前后和</td>
            </tr>
            <tr class="t_td_text">
                <td width="8%" class="caption_1">前(多)</td>
                <td class="colorRed bolds odds">{{ratedata['个数:前后和:前']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['个数:前后和:前']" @focus="quickbetFuns($event,'个数:前后和:前')"></td>
                <td width="8%" class="caption_1">后(多)</td>
                <td class="colorRed bolds odds">{{ratedata['个数:前后和:后']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['个数:前后和:后']" @focus="quickbetFuns($event,'个数:前后和:后')"></td>
                <td width="8%" class="caption_1">前后(和)</td>
                <td class="colorRed bolds odds">{{ratedata['个数:前后和:和']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['个数:前后和:和']" @focus="quickbetFuns($event,'个数:前后和:和')"></td>

            </tr>
        </table>
         <table class="wq text-center" border="0" cellpadding="0" cellspacing="1">
            <tr class="t_list_caption">
                <td colspan="9">单双和</td>
            </tr>
            <tr class="t_td_text">
                <td width="8%" class="caption_1">单(多)</td>
                <td class="colorRed bolds odds">{{ratedata['个数:单双和:单']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['个数:单双和:单']" @focus="quickbetFuns($event,'个数:单双和:单')"></td>
                <td width="8%" class="caption_1">双(多)</td>
                <td class="colorRed bolds odds">{{ratedata['个数:单双和:双']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['个数:单双和:双']" @focus="quickbetFuns($event,'个数:单双和:双')"></td>
                <td width="8%" class="caption_1">单双(和)</td>
                <td class="colorRed bolds odds">{{ratedata['个数:单双和:和']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['个数:单双和:和']" @focus="quickbetFuns($event,'个数:单双和:和')"></td>

            </tr>
        </table>
        <table class="wq text-center" border="0" cellpadding="0" cellspacing="1">
            <tr class="t_list_caption">
                <td colspan="15">五行</td>
            </tr>
            <tr class="t_td_text">
                <td width="8%" class="caption_1">金</td>
                <td class="colorRed bolds odds">{{ratedata['总和:五行:金']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['总和:五行:金']" @focus="quickbetFuns($event,'总和:五行:金')"></td>
                <td width="8%" class="caption_1">木</td>
                <td class="colorRed bolds odds">{{ratedata['总和:五行:木']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['总和:五行:木']" @focus="quickbetFuns($event,'总和:五行:木')"></td>
                <td width="8%" class="caption_1">水</td>
                <td class="colorRed bolds odds">{{ratedata['总和:五行:水']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['总和:五行:水']" @focus="quickbetFuns($event,'总和:五行:水')"></td>
                <td width="8%" class="caption_1">火</td>
                <td class="colorRed bolds odds">{{ratedata['总和:五行:火']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['总和:五行:火']" @focus="quickbetFuns($event,'总和:五行:火')"></td>
                <td width="8%" class="caption_1">土</td>
                <td class="colorRed bolds odds">{{ratedata['总和:五行:土']}}</td>
                <td><input type="text" class="moneyinp" v-model="moneydata['总和:五行:土']" @focus="quickbetFuns($event,'总和:五行:土')"></td>
            </tr>
        </table>
    </div>
</template>
<script>
    var timer = null;
    import axios from 'axios'
    import {lotterytype} from '../../../../assets/js/lotterytype.js'
    export default {
        name: "BjklAdd",
        props: {  //普通类型：String、Number、Boolean、Null    引用类型： Array、Object
            betmoney: {   //   下注金额
                type: String,
                required: true
            },
            resetinp: {   //   是否重填已下注金额  0为未下注  其他为已下注
                type: Number,
                required: true
            },
            openBet: {  //开奖  可下注
                type: Boolean,
                required: true
            },
            ninetime: {  //90s
                type: Number,
                required: true
            },
        },
        data(){
            return{
                ratedata: {},  //实时赔率
                params: {},  //菜单
                moneydata: {},
                betdataArr: [],  //下注 提交data
                nowitem: '',  //当前操作的下注item号
                arr: [],  //
            }
        },
        methods: {
            init(){
                var _this = this;
                // console.log(this.$route.query);

                this.params = lotterytype.apiParams(this.$route.query.id,this.$route.query.levelid);
                if(window.localStorage.Authorization){

                    _this.$httpGet('/api/game/listRate/'+ _this.params.nowlottery + '/' + _this.params.levellottery +'oa18').then(response => {
                        
                        if(response.status == 200){
                            _this.ratedata = response.data.rates;

                            if(response.data.need){

                                _this.$httpPost('/api/setting/rateItem/'+ _this.params.nowlottery + '/' + _this.params.levellottery +'oa18').then(response => {
                                
                                    if(response.status == 200){
                                        
                                    }

                                });
                                
                            }
                        }

                    });

                }
                
            },
            inits(){
                var _this = this;
                // console.log(this.$route.query);

                this.params = lotterytype.apiParams(this.$route.query.id,this.$route.query.levelid);
                if(window.localStorage.Authorization){

                    if (timer) {
                        clearInterval(timer);
                        timer = null;
                    }

                    _this.$httpGet('/api/game/listRate/'+ _this.params.nowlottery + '/' + _this.params.levellottery +'oa18').then(response => {
                        
                        if(response.status == 200){
                            _this.ratedata = response.data.rates;

                            if(response.data.need){

                                _this.$httpPost('/api/setting/rateItem/'+ _this.params.nowlottery + '/' + _this.params.levellottery +'oa18').then(response => {
                                
                                    if(response.status == 200){
                                        
                                    }

                                });
                                
                            }

                            timer = setInterval(() => {
                                _this.inits();
                            }, 10 * 1000)
                        }

                    });
                    
                }
                
                
            },
            //快捷下注
            quickbetFuns(ev,item,odds){
                var _this = this;
                if(_this.betmoney){

                    // Vue.set方法用来新增对象的属性。
                    _this.$set(_this.moneydata, item, _this.betmoney);
                    
                }
                _this.nowitem = item;
            },
            
        },
        mounted(){
            this.inits();
        },
        beforeDestroy(){
            clearInterval(timer);
        },
        watch :{
            resetinp: function(now,old){

                if(now != 0){   //重填下注金额

                    this.moneydata = {};  //清空所有下注金额
                    this.betdataArr = [];
                    this.arr = [];
                    
                }
            },
            moneydata: {
                
                //注意：当观察的数据为对象或数组时，curVal和oldVal是相等的，因为这两个形参指向的是同一个数据对象
　　　　　　　　　handler(newValue, oldValue) {

                    var _this = this;
        // 　　　　　　console.log(newValue[this.nowitem],newValue,this.nowitem)

                    if(newValue[_this.nowitem] != '' && newValue[_this.nowitem] != '0' && newValue[_this.nowitem] != undefined){

                        if (_this.arr.indexOf(_this.nowitem) == -1) {
                            _this.arr.push(_this.nowitem);
                            _this.betdataArr.push({'item': _this.nowitem,'value': newValue[_this.nowitem],'balls': []});
                        } else {
                            for(var i=0;i<_this.betdataArr.length;i++){

                                if(_this.nowitem == _this.betdataArr[i].item){
                                    _this.betdataArr[i].value= newValue[_this.nowitem];
                                }
                            }
                        }


                    }else{  //当前改变值为空

                        for(var i=0;i<_this.betdataArr.length;i++){

                            if(_this.betdataArr[i].item == _this.nowitem){
                                _this.betdataArr.splice(i,1);
                            }

                        }

                    }

                    var betdataObj = {};
                    betdataObj.game = _this.params.nowlottery;
                    betdataObj.items = _this.betdataArr;
                    
                    if(_this.betdataArr.length == 0){
                        _this.$emit('betdataObj',{});
                    }else{
                        _this.$emit('betdataObj',betdataObj);
                    }
                    // console.log('------watch',betdataObj);

        　　　　 },
        　　　　 deep: true
            },
            ninetime: function(now,old){
                console.log('------------90s  刷新');
                //90s  刷新数据
                this.init();
            },
            openBet: function(now,old){
                // console.log(now,old);
                this.init();
            },
        },
    }
</script>
